<?php
class ContactServiceImpl implements ContactService {

    public function __construct() {
        $this->contactDAO = new ContactSQLDAOImpl();
    }

    private $contactDAO;

    public function add(Contact $contact) {
        try {
            $this->contactDAO->create($contact);
        } catch (DataAccessException $e) {
            throw new ApplicationException($e->getMessage());
        }
    }

    public function getById($id) {
        try {
            return $this->contactDAO->read($id);
        } catch (DataAccessException $e) {
            throw new ApplicationException($e->getMessage());
        }
    }

    public function getContactsByUserId($id) {
        try {
            return $this->contactDAO->getContactsByUserId($id);
        } catch (DataAccessException $e) {
            throw new ApplicationException($e->getMessage());
        }
    }

    public function update(Contact $contact) {
        try {
            $this->contactDAO->update($contact);
        } catch (DataAccessException $e) {
            throw new ApplicationException($e->getMessage());
        }
    }

    public function deleteById($id) {
        try {
            $this->contactDAO->delete($id);
        } catch (DataAccessException $e) {
            throw new ApplicationException($e->getMessage());
        }
    }

}
?>
